//
//  NotificationView.m
//  coffee
//
//  Created by student4 on 2020/12/6.
//  Copyright © 2020 MOSAD. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "NotificationView.h"
#import "../../model/Notification.h"

@implementation NotificationView

@end

@implementation NotificationCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _state = [[UILabel alloc]initWithFrame:CGRectMake(20, 25, 10, 10)];
        _date = [[UILabel alloc]initWithFrame:CGRectMake(60, 10, 300, 20)];
        _msg = [[UILabel alloc]initWithFrame:CGRectMake(60, 30, 300, 20)];
        [self.contentView addSubview:self.state];
        [self.contentView addSubview:self.date];
        [self.contentView addSubview:self.msg];
        
        self.backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 5;
        self.layer.masksToBounds = YES;
    }
    
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
}
-(void)setupMsg:(Notification*)msg{
    if (msg == nil) {
        return;
    }
    if (![msg Read]) {
        [_state setText:@"!"];
    } else {
        [_state setText:@"-"];
    };
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:[msg CreateTime]/1000];
    [_date setText:[NSString stringWithFormat:@"%@",date]];
    NSString *action;
    if ([[msg Type]isEqualToString:@"comment"]) {
        action = @"评论了你的内容";
    } else if ([[msg Type]isEqualToString:@"like"]) {
        action = @"点赞了你的内容";
    }
    [_msg setText:[NSString stringWithFormat:@"用户%@%@",[msg Name],action]];
}
- (void)setFrame:(CGRect)frame
{
    frame.origin.y += 4;//整体向下 移动4
    frame.size.height -= 2;//间隔为2s
    [super setFrame:frame];
}
@end
